package com.eslserver.action.image;

import java.io.IOException;
import java.io.Writer;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.eslserver.core.aware.ESLAware;
import com.eslserver.dao.DAOException;
import com.eslserver.dao.ESLServerDAOFactory;
import com.eslserver.dao.ImageDAO;

@SuppressWarnings("serial")
public class DeleteAttachment extends HttpServlet implements ESLAware {
	public static final Logger LOG = LoggerFactory
			.getLogger(DeleteAttachment.class);

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		Writer writer = resp.getWriter();
		try {
			String imageID = req.getParameter(PARAM_IMAGE_ID);
			ImageDAO eslImageDAO = ESLServerDAOFactory.getDAOFactory(
					ESLServerDAOFactory.ESLSERVER_DAOFACTORY).getImageDAO();

			eslImageDAO.deleteImage(Integer.valueOf(imageID));
		} catch (DAOException e) {
			LOG.error("error deleting image", e);
		} finally {
			writer.close();
		}
	}
}
